<template>
    <!-- 一键搜 -->
    <div class="one-click-search white-box">
        <SearchPage v-if="showPage == 'searchPage'" @go-search="goSearch"></SearchPage>

        <SearchList v-else-if="showPage == 'searchList'" :searchCode="searchCode" :searchForm="searchForm" @click-backbtn="goBack"></SearchList>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';
import SearchPage from './SearchPage.vue';
import SearchList from './SearchList.vue';

export default {
    name: 'GoSearch',
    components: {
        SearchPage,
        SearchList
    },
    data() {
        return {
            showPage: 'searchPage',
            searchCode: '',
            searchForm: {},
            searchKey: ''
        };
    },
    created() {
        // 不使用
        // this.searchKey = window.sessionStorage.getItem('searchKey');
        // if (this.searchKey) {
        //     this.searchCode = this.searchKey;
        //     this.showPage = 'searchList';
        // }
    },
    mounted() {},
    computed: {
        ...mapGetters(['getSearchKey'])
    },
    watch: {
        searchKey: function(newVal, oldVal) {
            console.log(newVal, '12');
        }
    },
    methods: {
        goSearch(val, form) {
            this.searchCode = val;
            this.searchForm = form;
            this.showPage = 'searchList';
        },
        goBack() {
            this.showPage = 'searchPage';
        }
    }
};
</script>

<style lang="less" scoped>
.one-click-search.white-box {
    padding: 0rem;
}
</style>
